﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ToWaTimeReportMVC4.Models;

namespace ToWaTimeReportMVC4.Controllers
{
    public class ConsultController : Controller
    {
        ToWaService service = new ToWaService();
        //
        // GET: /Consult/

        public ActionResult Index()
        {
            return View(service.GetJobViewList(User.Identity.Name));
        }

        public ActionResult Rapport(int normal)
        {
            string start = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd HH:mm");
            string end = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
            Rapport r = service.GetRapportForConsultant(User.Identity.Name, start, end, normal);
            ViewBag.Consultant = r.ConsultantName;
            ViewBag.TotalHours = r.total;
            ViewBag.Overtime = r.overtime;
            ViewBag.NormalTime = normal;
            return View(r.ProjectJobs);
        }

        //
        // GET: /Consult/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Consult/Create

        public ActionResult Create()
        {
            return View(new JobView { Pro = service.GetProjectsDropDown() });
        } 

        //
        // POST: /Consult/Create

        [HttpPost]
        public ActionResult Create(JobView jobView)
        {
            try
            {
                User u = service.GetUserByUsername(User.Identity.Name);
                service.AddJobFromJobView(jobView, u.Id);
                return RedirectToAction("Index", "Consult");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Consult/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Consult/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Consult/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Consult/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
